#include "CMainMenuScene.h"
#include "CMainGameScene.h"
USING_NS_CC;
USING_NS_CC_EXT;


CCScene* CMainMenu::scene()
{
    CCScene *scene = CCScene::create();
	CMainMenu *layer = CMainMenu::create();
	scene->addChild(layer);
	return scene;
}

bool CMainMenu::init()
{
	if ( !CCLayer::init() )
    {
        return false;
    }

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
	
#pragma region bird
	CCScale9Sprite *blueBird = CCScale9Sprite::create("main_cha_blue.png");
	blueBird->setScale(0.625);
	CCControlButton *pBlue = CCControlButton::create(blueBird);
	pBlue->setPosition(ccp(120,340));
	pBlue->setAdjustBackgroundImage(false);
	this->addChild(pBlue,1);

	CCScale9Sprite *greenBird = CCScale9Sprite::create("main_cha_green.png");
	greenBird->setScale(0.625);
	CCControlButton *pGreen = CCControlButton::create(greenBird);
	pGreen->setPosition(ccp(150,220));
	pGreen->setAdjustBackgroundImage(false);
	this->addChild(pGreen,1);

	CCScale9Sprite *orangeBird = CCScale9Sprite::create("main_cha_orange.png");
	orangeBird->setScale(0.625);
	CCControlButton *pOrange = CCControlButton::create(orangeBird);
	pOrange->setPosition(ccp(75,260));
	pOrange->setAdjustBackgroundImage(false);
	this->addChild(pOrange,1);

	CCScale9Sprite *pinkBird = CCScale9Sprite::create("main_cha_pink.png");
	pinkBird->setScale(0.625);
	CCControlButton *pPink = CCControlButton::create(pinkBird);
	pPink->setPosition(ccp(140,270));
	pPink->setAdjustBackgroundImage(false);
	this->addChild(pPink,1);

	CCScale9Sprite *redBird = CCScale9Sprite::create("main_cha_red.png");
	redBird->setScale(0.625);
	CCControlButton *pRed = CCControlButton::create(redBird);
	pRed->setPosition(ccp(80,150));
	pRed->setAdjustBackgroundImage(false);
	this->addChild(pRed,1);

	CCScale9Sprite *whiteBird = CCScale9Sprite::create("main_cha_white.png");
	whiteBird->setScale(0.625);
	CCControlButton *pWhite = CCControlButton::create(whiteBird);
	pWhite->setPosition(ccp(120,430));
	pWhite->setAdjustBackgroundImage(false);
	this->addChild(pWhite,1);

	CCScale9Sprite *yellowBird = CCScale9Sprite::create("main_cha_yellow.png");
	yellowBird->setScale(0.625);
	CCControlButton *pYellow = CCControlButton::create(yellowBird);
	pYellow->setPosition(ccp(400,40));
	pYellow->setAdjustBackgroundImage(false);
	this->addChild(pYellow,1);

#pragma endregion

#pragma region Button
	nodeMainButton=CCNode::create();
	CCScale9Sprite* sClassicButton=CCScale9Sprite::create(s_sTex_Main_Menu_CLASSIC);
	sClassicButton->setScale(0.5f);
	CCScale9Sprite* sClassicHighlightedButton=CCScale9Sprite::create(s_sTex_Main_Menu_CLASSIC_PUSH);
	sClassicHighlightedButton->setScale(0.5f);
	CCControlButton* classicButton=CCControlButton::create(sClassicButton);
	classicButton->setAdjustBackgroundImage(false);
	classicButton->setBackgroundSpriteForState(sClassicHighlightedButton,CCControlStateHighlighted);
	classicButton->setPosition(ccp(310,330));
	classicButton->setRotation(-5);
	classicButton->addTargetWithActionForControlEvents(this,cccontrol_selector(CMainMenu::ControlButtonPressed),CCControlEventTouchDown);
	nodeMainButton->addChild(classicButton);

	CCScale9Sprite* sPandoraButton=CCScale9Sprite::create(s_sTex_Main_Menu_PANDORA);
	sPandoraButton->setScale(0.5f);
	CCScale9Sprite* sPandoraHighlightedButton=CCScale9Sprite::create(s_sTex_Main_Menu_PANDORA_PUSH);
	sPandoraHighlightedButton->setScale(0.5f);
	CCControlButton* pandoraButton=CCControlButton::create(sPandoraButton);
	pandoraButton->setAdjustBackgroundImage(false);
	pandoraButton->setBackgroundSpriteForState(sPandoraHighlightedButton,CCControlStateHighlighted);
	pandoraButton->setPosition(ccp(320,240));
	pandoraButton->setRotation(-5);
	//button->addTargetWithActionForControlEvents(this,cccontrol_selector(CMainMenu::outGame),CCControlEventTouchDown);
	nodeMainButton->addChild(pandoraButton);

	CCScale9Sprite* sIceButton=CCScale9Sprite::create(s_sTex_Main_Menu_ICE);
	sIceButton->setScale(0.5f);
	CCScale9Sprite* sIceHighlightedButton=CCScale9Sprite::create(s_sTex_Main_Menu_ICE_PUSH);
	sIceHighlightedButton->setScale(0.5f);
	CCControlButton* iceButton=CCControlButton::create(sIceButton);
	iceButton->setAdjustBackgroundImage(false);
	iceButton->setBackgroundSpriteForState(sIceHighlightedButton,CCControlStateHighlighted);
	iceButton->setPosition(ccp(330,150));
	iceButton->setRotation(-5);
	//button->addTargetWithActionForControlEvents(this,cccontrol_selector(CMainMenu::outGame),CCControlEventTouchDown);
	nodeMainButton->addChild(iceButton);

	CCScale9Sprite* sOptButton=CCScale9Sprite::create(s_sTex_Main_Menu_OPT);
	sOptButton->setScale(0.5f);
	CCScale9Sprite* sOptHighlightedButton=CCScale9Sprite::create(s_sTex_Main_Menu_OPT_PUSH);
	sOptHighlightedButton->setScale(0.5f);
	CCControlButton* optButton=CCControlButton::create(sOptButton);
	optButton->setAdjustBackgroundImage(false);
	optButton->setBackgroundSpriteForState(sOptHighlightedButton,CCControlStateHighlighted);
	optButton->setPosition(ccp(47,86));
	//button->addTargetWithActionForControlEvents(this,cccontrol_selector(CMainMenu::outGame),CCControlEventTouchDown);
	nodeMainButton->addChild(optButton);

	CCScale9Sprite* sRankButton=CCScale9Sprite::create(s_sTex_Main_Menu_RANK);
	sRankButton->setScale(0.5f);
	CCScale9Sprite* sRankHighlightedButton=CCScale9Sprite::create(s_sTex_Main_Menu_RANK_PUSH);
	sRankHighlightedButton->setScale(0.5f);
	CCControlButton* rankButton=CCControlButton::create(sRankButton);
	rankButton->setAdjustBackgroundImage(false);
	rankButton->setBackgroundSpriteForState(sRankHighlightedButton,CCControlStateHighlighted);
	rankButton->setPosition(ccp(142,86));
	//button->addTargetWithActionForControlEvents(this,cccontrol_selector(CMainMenu::outGame),CCControlEventTouchDown);
	nodeMainButton->addChild(rankButton);
	this->addChild(nodeMainButton,1);
#pragma endregion
	
#pragma region Background
	nodeBG=CCNode::create();
	CCSprite *pMain_Menu_BG = CCSprite::create(s_sTex_Main_Menu_BG);
	pMain_Menu_BG->setAnchorPoint(ccp(0,0));
	pMain_Menu_BG->setRotation(-5);
	pMain_Menu_BG->setPosition(ccp(206,58));
	pMain_Menu_BG->setScale(0.625);
	nodeBG->addChild(pMain_Menu_BG,1);

	CCSprite *pMain_Menu_Title = CCSprite::create(s_sTex_Main_Menu_TITLE);
	pMain_Menu_Title->setAnchorPoint(ccp(0,0));
	pMain_Menu_Title->setPosition(ccp(100,800));
	pMain_Menu_Title->runAction(CCMoveTo::create(1.5f,ccp(100,480)));
	pMain_Menu_Title->setScale(0.625);
	nodeBG->addChild(pMain_Menu_Title,2);

	CCSprite *pMain_Menu_BG_TREE_A = CCSprite::create(s_sTex_Main_Menu_BG_Tree_A);
	pMain_Menu_BG_TREE_A->setAnchorPoint(ccp(0,1));
	pMain_Menu_BG_TREE_A->setPosition(ccp(0,640));
	pMain_Menu_BG_TREE_A->setScale(0.625);
	nodeBG->addChild(pMain_Menu_BG_TREE_A,1);

	CCSprite *pMain_Menu_BG_TREE_B = CCSprite::create(s_sTex_Main_Menu_BG_Tree_B);
	pMain_Menu_BG_TREE_B->setAnchorPoint(ccp(1,1));
	pMain_Menu_BG_TREE_B->setPosition(ccp(480,640));
	pMain_Menu_BG_TREE_B->setScale(0.625);
	nodeBG->addChild(pMain_Menu_BG_TREE_B,1);

	CCSprite *pMain_Menu_BG_C = CCSprite::create(s_sTex_Main_Menu_BG_C);
	pMain_Menu_BG_C->setAnchorPoint(ccp(0,1));
	pMain_Menu_BG_C->setPosition(ccp(0,640));
	pMain_Menu_BG_C->setScale(0.625);
	nodeBG->addChild(pMain_Menu_BG_C,0);

	CCSprite *pMain_Menu_BG_B = CCSprite::create(s_sTex_Main_Menu_BG_B);
	pMain_Menu_BG_B->setAnchorPoint(ccp(0,0));
	pMain_Menu_BG_B->setPosition(ccp(0,71.25f));
	pMain_Menu_BG_B->setScale(0.625);
	nodeBG->addChild(pMain_Menu_BG_B,0);

	CCSprite *pMain_Menu_BG_A = CCSprite::create(s_sTex_Main_Menu_BG_A);
	pMain_Menu_BG_A->setAnchorPoint(ccp(0,0));
	pMain_Menu_BG_A->setPosition(ccp(0,0));
	pMain_Menu_BG_A->setScale(0.625);
	nodeBG->addChild(pMain_Menu_BG_A,2);
	this->addChild(nodeBG,0);

#pragma endregion

	 return true;
}
void CMainMenu::ControlButtonPressed(CCObject* sender,CCControlEvent controlevent)
{
	CCDirector::sharedDirector()->replaceScene(CMainGame::scene());
}